import matplotlib.pyplot as plt
import numpy as np
import re

def to_xy(sy_str):
    x, y = sy_str.split(',')
    return float(x), float(y)

def plot_scatter(ax, str_line, size = 1, color = 'blue', alpha = 0.5):
    result = re.findall(r'\((.*?)\)', str_line) 
    occ_point_list = []
    for point_index, xy_str in enumerate(result):
        row, col = to_xy(xy_str)
        occ_point_list.append([row, col])

    row_list = [row for row, col in occ_point_list]
    col_list = [col for row, col in occ_point_list]

    scatter = ax.scatter(
        row_list,
        col_list,
        s=size,
        c=color,
        alpha = alpha
    )


if __name__ == "__main__":
    FILE = 'res/occupancy_data.txt'
    
    with open(FILE, 'r') as fd:
        data = fd.readlines()
    
    map_row_size = float(data[0])
    map_col_size = float(data[1])

    fig, ax = plt.subplots()
    plot_scatter(ax, data[2], 1.5, 'red', 1.0) # BOUNDARY
    plot_scatter(ax, data[3], 0.5, 'blue', 0.1) # INSIDE

    ax.set_aspect(1.0)
    ax.grid(True, which='both', linestyle='--', linewidth=0.5)
    ax.set_xticks(np.arange(0, map_row_size + 1, 50.0))  # x轴刻度步长5
    ax.set_yticks(np.arange(0, map_col_size + 1, 50.0))  # y轴刻度步长5
    
    plt.title("OBS_Occupancy")
    plt.savefig('res/occupancy.jpg')
    plt.show()